<?php

namespace app\common\model\examination;

use app\common\library\helper;
use app\common\model\BaseModel;

/**
 * 课程模型
 */
class ExaminationUserAward extends BaseModel
{
    protected $name = 'ExaminationUserAward';
    protected $pk = 'id';

    protected $append = [
        'status_text',

    ];
    /**
     * 设置课程开始时间
     */
    public function setStartTimeAttr($value)
    {
        return $value ? strtotime($value) : 0;
    }

    /**
     * 设置课程结束时间
     */
    public function setEndTimeAttr($value)
    {
        return $value ? strtotime($value) : 0;
    }

    /**
     * 获取课程详情
     */
    public static function detail($where, $with = ['user','award.image','log'])
    {
        !is_array($where) && $where = ['id' => (int)$where];
        return (new static())->where($where)->with($with)->find();
    }
    public function getStatusTextAttr($value, $data)
    {

        // 付款状态
        if ($data['status'] == 0) {
            return '待发放';
        }
        // 付款状态
        if ($data['status'] == 1) {
            return '已发放';
        }
        return $value;
    }

    /**
     * 关联封面图片表
     */
    public function user()
    {
        return $this->belongsTo('app\\common\\model\\user\\User', 'user_id', 'user_id');
    }

    public function award()
    {
        return $this->belongsTo('app\\common\\model\\examination\\ExaminationAward', 'award_id', 'id');
    }


    public function log()
    {
        return $this->belongsTo('app\\common\\model\\examination\\ExaminationLog', 'award_id', 'id');
    }




}
